﻿/*正则表达式参考
 * http://cn.voidcc.com/question/p-ufywvtte-vx.html
 * 正则知乎参考
 * https://www.zhihu.com/question/46667578/answer/102256163
 * 解释库参考
 * https://archive.codeplex.com/?p=irony
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CodeTextLine
{
    Color keywordCOlor = new Color(1,1,1);
    Color functionColor = Color.cyan;
    List<string> keyWords = new List<string>();
    public CodeTextLine() {
        keyWords = new List<string>() {
            "if",
            "else",
            "bool",
            "float",
            "float3",
            "float4",
            "return"
        };
    }
    public string Wrap(string line)
    {
        string lineWithoutPre = line.TrimStart();
        string lineTurn = "";
        foreach (var word in keyWords)
        {
            if (lineWithoutPre.Substring(0, word.Length + 1) == word + " ")
            {
//                lineTurn =$"<color=red>{word}</color>" +lineWithoutPre.Substring(word.Length);
                lineTurn =string.Format("<color=red>{0}</color>",word) +lineWithoutPre.Substring(word.Length);
                break;
            }
        }
        return lineTurn;
    }
}
